var boomBoomCowboy = {};

var levelData;

window.addEventListener("load", function() {
		Modernizr.load([{
			load : [
				// Libraries
				"lib/easeljs.min.js",
				"lib/Box2dWeb-2.1.a.3.min.js",
				"lib/state-machine.min.js",
				
				// Code
				"js/game.js",
				"js/statemanager.js",
				// Images
			],
			complete : function() {	
				$.getJSON("data/levels.js", function(data){
					levelData = data;
					JSONLoaded();
				});
				
				function JSONLoaded() {
					// Add click listeners to menu items
					$("#menuscreen li").each(function(index, li) {
						$(li).click(menuItemClicked);
					});
					
					$("#returnToMenu").click(function() {
						boomBoomCowboy.stateManager.instance.returnToMenu();
					});
					
					// Go to main menu
					boomBoomCowboy.stateManager.instance.startup();
				}
				
				function menuItemClicked(event) {
					var sm = boomBoomCowboy.stateManager.instance;
					// sm.start();
					// console.log(event);
					
					switch (event.target.innerText) {
						case "Start Game":
							sm.start();
							break;
							
						case "Help":
							sm.showHelp();
							break;
							
						case "Credits":
							sm.showCredits();
							break;
					}
				}
			}
		}])
}, false);